#ifndef ENCODEVIDEO_H
#define ENCODEVIDEO_H

#include<QThread>
#include<QDebug>
#include<QQueue>
#include<QDateTime>
#include"model/basemodel.h"
#include"contrl/mycontrol.h"
#include"data/device.h"
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavdevice/avdevice.h"
#include "libavfilter/avfilter.h"
#include "libavformat/avformat.h"
#include "libavutil/avutil.h"
#include "libpostproc/postprocess.h"
#include "libswresample/swresample.h"
#include "libswscale/swscale.h"
}
class EncodeVideo : public QThread
{
    Q_OBJECT
public:
    ~EncodeVideo();
    EncodeVideo();

    void register_all();
    void initEncode();
    void writeTailtewr();


    bool getSt() const;
    void setSt(bool value);

    bool getIsClose() const;
    void setIsClose(bool value);

    bool getIsStop() const;
    void setIsStop(bool value);

    QString getVideooutName() const;
    void setVideooutName(const QString &value);

    QString getVideooutPath() const;
    void setVideooutPath(const QString &value);

    int getWight() const;
    void setWight(int value);

    int getHight() const;
    void setHight(int value);

    AVCodecContext *getCodecContex() const;
    void setCodecContex(AVCodecContext *value);


public slots:
    void CloseFile();
    void reciverYUV(AVFrame*yuv);

    void reciverExit();

    void reciverWightHight(int w,int h);




signals:
     void sendTimeMax();
     void sendWriteDateBase();

private:
    AVFormatContext*formatContex;
    AVCodecContext*codecContex;
    AVPacket*pkt;
    int pktIndex=0;
    QQueue<AVFrame*>YuvQueue;
    bool st=0;
    bool isStop=0;
    QString videooutName;
    QString videooutPath;

    bool isClose=0;
    // QThread interface


    int wight;
    int hight;


    MyControl*con;
    BaseModel*model;
    int x=0;

//    AVRational time_base;
//    int frame_count;


protected:
    void run();


};

#endif // ENCODEVIDEO_H
